﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service.BAL;

namespace Service.DAL
{
    public class ChiTietNhapHang_DAL
    {
        public static List<ChiTietNhapHang_BAL> GetAllByID(string strMaNhapHang)
        {
            List<ChiTietNhapHang_BAL> result = new List<ChiTietNhapHang_BAL>();
            try
            {
                var nhapHang = from nh in Common_DAL.storeData.ChiTietNhapHangs
                               where nh.MaNhapHang == strMaNhapHang
                               select new ChiTietNhapHang_BAL()
                               {
                                   MaSanPham = nh.MaSanPham,
                                   SoLuong = (int)nh.SoLuong,
                                   DonGia = (float)nh.DonGia,
                                   ThoiDiemNhap = (DateTime)nh.ThoiDiemNhap,
                                   MaNhapHang = nh.MaNhapHang
                               };
                result = nhapHang.ToList<ChiTietNhapHang_BAL>();
            }
            catch
            {

            }
            return result;
        }

        public static void Insert(ChiTietNhapHang_BAL chiTietNhapHang_BAL)
        {
            Common_DAL.storeData.TaoPhieuChiTietNhapHang(chiTietNhapHang_BAL.MaNhapHang, chiTietNhapHang_BAL.MaSanPham, chiTietNhapHang_BAL.SoLuong, chiTietNhapHang_BAL.DonGia, chiTietNhapHang_BAL.ThoiDiemNhap);
            Common_DAL.storeData.SubmitChanges();
        }
    }
}
